package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingLevelPageParamVo;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> getAll() {
        List<NursingLevel> all = nursingLevelMapper.getAll();
        List<NursingLevelVo> nursingLevelVos = BeanUtil.copyToList(all, NursingLevelVo.class);
        return nursingLevelVos;
    }

    @Override
    public void add(NursingLevelDto nursingLevelDto) {
        System.out.println("================================="+nursingLevelDto);
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.add(bean);
    }

    @Override
    public PageResponse<NursingLevelVo> getByPage(NursingLevelPageParamVo paramVo) {

        PageHelper.startPage(paramVo.getPageNum(), paramVo.getPageSize());
        List<NursingLevel> list=nursingLevelMapper.getByPage(paramVo);
        Page<NursingLevel> list1 = (Page<NursingLevel>) list;
        return PageResponse.of(list1,NursingLevelVo.class);
    }

    @Override
    public NursingLevelVo getById(Integer id) {
        NursingLevel nursingLevel=nursingLevelMapper.getById(id);
        NursingLevelVo bean = BeanUtil.toBean(nursingLevel, NursingLevelVo.class);
        return bean;
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(bean);
    }

    @Override
    public void delete(Integer id) {
        nursingLevelMapper.delete(id);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        nursingLevelMapper.updateStatus(id,status);
    }
}
